package cn.ddiancan.xddcloud.psc.flow.feign;

import java.util.Date;
import java.util.List;

import cn.ddiancan.xddcloud.psc.flow.utils.Assert;
import cn.ddiancan.xddcloud.psc.flow.entity.XddTask;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 任务数据访问层接口
 */
@FeignClient(contextId = "XddTaskService", name = "xddcloud-flow-server")
public interface XddTaskRemoteService {

    @PostMapping("/flow/task/insert")
    boolean insert(XddTask task);

    @DeleteMapping("/flow/task/deleteById/{id}")
    boolean deleteById(@PathVariable("id") Long id);

    @DeleteMapping("/flow/task/deleteByInstanceIds")
    boolean deleteByInstanceIds(@RequestBody List<Long> instanceIds);

    @DeleteMapping("/flow/task/deleteByIds")
    boolean deleteByIds(@RequestBody List<Long> ids);

    @PutMapping("/flow/task/updateById")
    boolean updateById(@RequestBody XddTask flwTask);

    @GetMapping("/flow/task/selectById/{id}")
    XddTask selectById(@PathVariable("id") Long id);

    default XddTask selectCheckById(Long id) {
        XddTask task = selectById(id);
        Assert.isNull(task, "The specified task [id=" + id + "] does not exist");
        return task;
    }

    @GetMapping("/flow/task/selectCountByParentTaskId/{parentTaskId}")
    Long selectCountByParentTaskId(@PathVariable("parentTaskId") Long parentTaskId);

    @GetMapping("/flow/task/selectListByInstanceId/{instanceId}")
    List<XddTask> selectListByInstanceId(@PathVariable("instanceId") Long instanceId);

    @GetMapping("/flow/task/selectListByInstanceIdAndTaskName/{instanceId}/{taskName}")
    List<XddTask> selectListByInstanceIdAndTaskName(@PathVariable("instanceId") Long instanceId, @PathVariable("taskName") String taskName);

    @GetMapping("/flow/task/selectListByInstanceIdAndTaskKey/{instanceId}/{taskKey}")
    List<XddTask> selectListByInstanceIdAndTaskKey(@PathVariable("instanceId") Long instanceId, @PathVariable("taskKey") String taskKey);

    @PostMapping("/flow/task/selectListByInstanceIdAndTaskNames/{instanceId}")
    List<XddTask> selectListByInstanceIdAndTaskNames(@PathVariable("instanceId") Long instanceId, @RequestBody List<String> taskNames);

    @GetMapping("/flow/task/selectListTimeoutOrRemindTasks")
    List<XddTask> selectListTimeoutOrRemindTasks(Date currentDate);

    @GetMapping("/flow/task/selectListByParentTaskId/{parentTaskId}")
    List<XddTask> selectListByParentTaskId(@PathVariable("parentTaskId") Long parentTaskId);

    @PostMapping("/flow/task/selectListByParentTaskIds")
    List<XddTask> selectListByParentTaskIds(@RequestBody List<Long> parentTaskIds);
}
